package ui.frame.dialog;

import static constants.GTextbookConstants.User_Name;
import static constants.GTextbookConstants.language;

import java.awt.event.ActionEvent;

import ui.Utility;
import ui.frame.GTFrame;
import ui.frame.GTextbook;
import ui.frame.dialog.dialogInterface.modifyDialog;
import ui.view.DnDIndexTree;
import ui.view.GTView;
import ui.view.IndexTreeView;
import ui.view.NodeInfo;
import ui.view.IndexTreeNode;

public class ModifyPropositionDialog extends PropositionDialog implements modifyDialog{
	  public ModifyPropositionDialog(IndexTreeNode node,GTextbook theApp, GTFrame window, int language) {
		  super(theApp, theApp.getWindow(),((NodeInfo)(node.getUserObject())).getRender().getRoleNum(), language);
		  this.node = node;
	  }
	  
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			if(e.getSource() == cancel){
				this.dispose();
			}
			if(e.getSource() == ok){
			
			    //do the modifying job
				if(Utility.removeFromKB(((NodeInfo)(node.getUserObject())).getKnowledgeID(), typeInString)){
					if(complete()){
						//modify the node

					}
				}
			}
		}
		
		public void modifyNode(IndexTreeNode node) {
			// TODO Auto-generated method stub
			String name = this.getBasicPanel().getNamePanel().getTextField().getText();	
	        NodeInfo nodeInfo = new NodeInfo(User_Name,typeInString, Utility.getKnowledgeNameFromInput(name));
			DnDIndexTree tree = (DnDIndexTree)((IndexTreeView)(((GTView)(theApp.getView())).getIndexTabbedPane().getSelectedComponent())).getIndexTree();
			tree.modifyWithChecking(node, nodeInfo);

		}
	  
	  private IndexTreeNode node;

	public IndexTreeNode getNode() {
		// TODO Auto-generated method stub
		return node;
	}
}
